import { Component, ViewChild } from '@angular/core';
import { Http } from '@angular/http';
import { RiskBaseComponent } from '../../shared/components/riskBase.component';
//embedded components
import { RatingOverviewSummaryComponent } from './components/ratingOverview.component';
import { AnalystViewSummaryComponent } from './components/analystView.component';
import { KeyIssuesSummaryComponent } from './components/keyIssues.component';
import { SubIndustrySummaryComponent } from './components/subIndustry.component';
//Services
import { CompanyRiskService } from '../companyRisk.service';

@Component({  
  templateUrl: './summary.component.html'
})
//parent component in charge with the preloader
export class CompanyRiskSummaryComponent extends RiskBaseComponent {  
  public subPeerGroup: string;

  @ViewChild('ratingOverview') ratingOverview: RatingOverviewSummaryComponent;    
  @ViewChild('analystView') analystView: AnalystViewSummaryComponent;
  @ViewChild('keyIssues') issues: KeyIssuesSummaryComponent;
  @ViewChild('subIndustry') subIndustry: SubIndustrySummaryComponent;

  constructor(
    private riskService: CompanyRiskService,
    private http: Http) {
    super(http);
}

  ngOnInit(){
    this.gaService.showPreloader();

    this.riskService.company.then((company) => {  
      this.subPeerGroup = company.subPeerGroup;
    })
  }

  ngAfterViewInit(){
    Promise.all([this.ratingOverview.loaded, this.analystView.loaded, this.issues.loaded, this.subIndustry.loaded]).then(() => {      
      this.gaService.hidePreloader();
    });
  }
}